package cn.wsgfz.test;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.BaseAdapter;

public abstract class AbsAdapter<T> extends BaseAdapter {
	private List<T> mResource;
	private Context mContext;
	private int mColumnNum;
	
	public AbsAdapter(Context c, List<T> resource, int col) {
		this.mResource  = resource;
		this.mContext   = c;
		this.mColumnNum = col; 
	}
	
	@Override
	public int getCount() {
		return mResource.size() / mColumnNum;
	}

	@Override
	public Object getItem(int index) {
		return mResource.get(index);
	}

	@Override
	public long getItemId(int index) {
		return index;
	}
	
	protected List<T> getResource() {
		return this.mResource;
	}
	
	public View getView(int layoutId) {
		LayoutInflater inflater = LayoutInflater.from(mContext);
		View v = inflater.inflate(layoutId, null);
		return v;
	}
	
	public void notifyResource(List<T> res) {
		this.mResource = res;
		notifyDataSetChanged();
	}
	
	public Context getContext() {
		return this.mContext;
	}
}
